<template>
  <view>
    <!-- 收货地址区域 -->
    <view class="address-box" v-if="JSON.stringify(addressInfo) === '{}'">
      <button type="primary" size="mini" class="box-button" @click="changeAddress">请选择收货地址+</button>
    </view>
    <!-- 收货信息的盒子 -->
    <view class="address-info" v-else @click="changeAddress">
      <view class="row1">
        <!-- 左侧信息 -->
        <view class="row1-left">
          <view class="row1-name">收货人：{{addressInfo.userName}}</view>
        </view>
        <!-- 右侧信息 -->
        <view class="row1-right">
          <view class="row1-phone">电话：{{addressInfo.telNumber}}</view>
          <uni-icons type="arrowright" size="16"></uni-icons>
        </view>
      </view>
      <view class="row2">
        <view class="row2-left">收货地址：</view>
        <view class="row2-right">{{addressStr}}</view>
      </view>
    </view>
    <!-- 底部边框线 -->
    <view class="img"></view>
  </view>
</template>

<script>
  import { mapState, mapMutations, mapGetters } from 'vuex'
  
  export default {
    name:"my-address",
    data() {
      return {
        // 收货地址信息
        // addressInfo: {}
      };
    },
    computed: {
      ...mapState('m_user', ['addressInfo']),
      ...mapGetters('m_user', ['addressStr'])
      
    },
    methods: {
      ...mapMutations('m_user', ['updateAddress']),
      // 点击添加收货地址按钮
      async changeAddress() {
        const [error, succuse] = await uni.chooseAddress({
          
        }).catch(error => error)
        if (error === null && succuse.errMsg === 'chooseAddress:ok') {
          this.updateAddress(succuse)
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .address-box{
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
.img{
  width: 100%;
  // height: 5px;
  border-bottom: 2px solid tomato;
}
.address-info{
  font-size: 12px;
  height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 5px;
  .row1{
    display: flex;
    justify-content: space-between;
    .row1-left{}
    .row1-right{
      display: flex;
      align-items: center;
    }
  }
  .row2{
    display: flex;
    align-items: center;
    margin-top: 10px;
    .row2-left{
      white-space: nowrap;
    }
    .row2-right{}
  }
}
</style>